package com.czk.netty.netty.inboundandoutboundhandler.client;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * 出站
 *
 * @Author:ChenZhangKun
 * @Date: 2021/1/20 22:44
 */
public class MyLongToByteEncoder extends MessageToByteEncoder<Long> {
    /**
     * MessageToByteEncoder 里有个write方法，其会判断编码类型是否和handler处理的类型一致，一致才会进行编码
     * @param channelHandlerContext
     * @param aLong
     * @param byteBuf
     * @throws Exception
     */
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Long aLong, ByteBuf byteBuf) throws Exception {
        System.out.println("MyLongToByteEncoder的encode方法被调用");
        System.out.println("msg=" + aLong);
        byteBuf.writeLong(aLong);
    }
}
